package com.ruoyi.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.basic.MesBomDetail;
import com.ruoyi.service.basic.IMesBomDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * BOM明细Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/mes/bomDetail")
public class MesBomDetailController extends BaseController
{
    @Autowired
    private IMesBomDetailService mesBomDetailService;

    /**
     * 查询BOM明细列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesBomDetail mesBomDetail)
    {
        startPage();
        List<MesBomDetail> list = mesBomDetailService.selectMesBomDetailList(mesBomDetail);
        return getDataTable(list);
    }

    /**
     * 导出BOM明细列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:export')")
    @Log(title = "BOM明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBomDetail mesBomDetail)
    {
        List<MesBomDetail> list = mesBomDetailService.selectMesBomDetailList(mesBomDetail);
        ExcelUtil<MesBomDetail> util = new ExcelUtil<MesBomDetail>(MesBomDetail.class);
        util.exportExcel(response, list, "BOM明细数据");
    }

    /**
     * 获取BOM明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(mesBomDetailService.selectMesBomDetailByDetailId(detailId));
    }

    /**
     * 新增BOM明细
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:add')")
    @Log(title = "BOM明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBomDetail mesBomDetail)
    {
        return toAjax(mesBomDetailService.insertMesBomDetail(mesBomDetail));
    }

    /**
     * 修改BOM明细
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:edit')")
    @Log(title = "BOM明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBomDetail mesBomDetail)
    {
        return toAjax(mesBomDetailService.updateMesBomDetail(mesBomDetail));
    }

    /**
     * 删除BOM明细
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:remove')")
    @Log(title = "BOM明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(mesBomDetailService.deleteMesBomDetailByDetailIds(detailIds));
    }

    /**
     * 根据BOM ID查询明细列表
     */
    @GetMapping("/getByBomId/{bomId}")
    public AjaxResult getByBomId(@PathVariable Long bomId)
    {
        List<MesBomDetail> list = mesBomDetailService.selectMesBomDetailByBomId(bomId);
        return success(list);
    }

    /**
     * 批量新增BOM明细
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:add')")
    @Log(title = "BOM明细", businessType = BusinessType.INSERT)
    @PostMapping("/batchInsert")
    public AjaxResult batchInsert(@RequestBody List<MesBomDetail> mesBomDetailList)
    {
        return toAjax(mesBomDetailService.batchInsertMesBomDetail(mesBomDetailList));
    }

    /**
     * 根据BOM ID删除明细
     */
    @PreAuthorize("@ss.hasPermi('mes:bomDetail:remove')")
    @Log(title = "BOM明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteByBomId/{bomId}")
    public AjaxResult deleteByBomId(@PathVariable Long bomId)
    {
        return toAjax(mesBomDetailService.deleteMesBomDetailByBomId(bomId));
    }
}